package com.shycloud.mido.homework.controller;

import java.util.Map;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.google.api.client.util.ArrayMap;
import com.shycloud.mido.common.core.util.R;
import com.shycloud.mido.homework.api.entity.ZebraHomeworkAssist;
import com.shycloud.mido.homework.api.entity.ZebraHomeworkLeaveMessage;
import com.shycloud.mido.homework.service.ZebraHomeworkAssistService;
import com.shycloud.mido.homework.service.ZebraHomeworkLeaveMessageService;

import lombok.AllArgsConstructor;

/**
 * 作业辅导模块 controller
 *
 * @author nianhua.jiang
 * @date 2021/1/5 9:38
 **/
@RestController

@AllArgsConstructor
@RequestMapping("/assist")
public class HomeworkAssistController {

	/** 作业辅导模块 service */
	private ZebraHomeworkAssistService assistService;
	/** 作业辅导留言模块 service */
	private ZebraHomeworkLeaveMessageService leaveMessageService;

	/**
	 * 保存作业辅导
	 *
	 * @param assist - 辅导信息
	 * @return com.shycloud.mido.common.core.util.R
	 * @author nianhua.jiang
	 * @date 2021/1/5 9:38
	 **/
	@PostMapping("saveAssist")
	public R saveAssist(@RequestBody ZebraHomeworkAssist assist) {

		Map<String, String> res = new ArrayMap<>();

		res.put("id", assistService.saveAssist(assist));

		return new R(res);
	}

	/**
	 * 删除作业辅导
	 *
	 * @param requestMap
	 * @return com.shycloud.mido.common.core.util.R
	 * @author nianhua.jiang
	 * @date 2021/1/5 9:38
	 **/
	@PostMapping("delAssist")
	public R delAssist(@RequestBody Map<String, Object> requestMap) {

		//获取作业辅导ID
		String assistId = (String) requestMap.get("assistId");

		return new R(assistService.delAssist(assistId));
	}

	/**
	 * 获取作业辅导信息
	 *
	 * @param homeworkId
	 * @return com.shycloud.mido.common.core.util.R
	 * @author nianhua.jiang
	 * @date 2021/1/5 9:38
	 **/
	@GetMapping("getAssist")
	public R getAssist(String homeworkId) {
		return new R(assistService.getAssist(homeworkId));
	}

	/**
	 * 留言
	 *
	 * @param leaveMessage
	 * @return com.shycloud.mido.common.core.util.R
	 * @author nianhua.jiang
	 * @date 2021/1/13 14:46
	 **/
	@PostMapping("leaveMessage")
	public R leaveMessage(@RequestBody ZebraHomeworkLeaveMessage leaveMessage) {
		return new R(leaveMessageService.save(leaveMessage));
	}

	/**
	 * 获取留言信息
	 *
	 * @param homeworkId
	 * @return com.shycloud.mido.common.core.util.R
	 * @author nianhua.jiang
	 * @date 2021/1/13 14:55
	 **/
	@GetMapping("getLeaveMessage")
	public R getLeaveMessage(String homeworkId) {
		return new R(leaveMessageService.getLeaveMessage(homeworkId));
	}

	/**
	 * 删除留言
	 *
	 * @param requestMap
	 * @return com.shycloud.mido.common.core.util.R
	 * @author nianhua.jiang
	 * @date 2021/1/13 15:08
	 **/
	@PostMapping("delLeaveMessage")
	public R delLeaveMessage(@RequestBody Map<String, Integer> requestMap) {

		Integer id = requestMap.get("id");

		return new R(leaveMessageService.removeById(id));
	}

}
